﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;

namespace TaxiDispatchClient
{
    public partial class TaxiInfoForm : DevExpress.XtraEditors.XtraForm
    {
        public TaxiInfoForm()
        {
            InitializeComponent();
        }

        private void TaxiInfoForm_Load(object sender, EventArgs e)
        {
            try
            {
                string strWhere = "";
                if (MainForm.MyUserInfo.CompanyName!=Service.PowerConfig.MainCompanyName)
                {
                    strWhere = "CompanyName like'" + 
                        MainForm.MyUserInfo.CompanyName + "%'";
                }
                DataSet ds = MainForm.PositionService.TaxiInfoGetList(strWhere);
                gridControl1.DataSource = ds.Tables[0];
                //gridView1.Columns["id"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                //gridView1.Columns["id"].AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                //gridView1.Columns["id"].Caption = "流水号";
                //gridView1.Columns["id"].Width = 40;
                //gridView1.Columns["TaxiNo"].Caption = "出租车牌照";
                //gridView1.Columns["TaxiNo"].Width = 55;
                //gridView1.Columns["TaxiType"].Caption = "出租车车型（颜色）";
                //gridView1.Columns["TaxiType"].Width = 100;
                //gridView1.Columns["Taxigroup"].Caption = "所属分组";
                //gridView1.Columns["TaxiGroupid"].Visible = false;
                //gridView1.Columns["Remark"].Caption = "备注信息";

            }
            catch (Exception ex)
            {
                Common.CommonRoutine.HandlingExceptions(ex, true);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            Close();
        }

        private void simpleButton_Select_Click(object sender, EventArgs e)
        {
            try
            {
                string parameterVaule = txtEdt_condition.Text;
                string parameter = radioGroup_SelectType.SelectedIndex == 0 ? "TaxiNo" : "TaxiType";
                //DataSet ds = MainForm.PositionService.TaxiInfoGetListWithPar(parameter, parameterVaule);
                //gridControl1.DataSource = ds.Tables[0];

                StringBuilder strWhere = new StringBuilder();
                if (parameterVaule.Trim()!="")
                {
                    strWhere.Append(parameter);
                    strWhere.Append(" like '%");
                    strWhere.Append(parameterVaule);
                    strWhere.Append("%' ");
                    if (MainForm.MyUserInfo.CompanyName != Service.PowerConfig.MainCompanyName)
                    {
                        strWhere.Append(" and CompanyName ='");
                        strWhere.Append(MainForm.MyUserInfo.CompanyName);
                        strWhere.Append("'");                    
                    }

                }
                else
                {
                    if (MainForm.MyUserInfo.CompanyName != Service.PowerConfig.MainCompanyName)
                    {
                        strWhere.Append(" CompanyName ='");
                        strWhere.Append(MainForm.MyUserInfo.CompanyName);
                        strWhere.Append("'");
                    } 
                }
                DataSet ds = MainForm.PositionService.TaxiInfoGetList(strWhere.ToString());
                gridControl1.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                Common.CommonRoutine.HandlingExceptions(ex, true);
            }
        }
        Point _mouseOff;
        bool _leftFlag;
        private void Form_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _mouseOff = new Point(-e.X, -e.Y);
                _leftFlag = true;
            }
        }

        private void Form_MouseMove(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(_mouseOff.X, _mouseOff.Y);
                Location = mouseSet;
            }
        }

        private void Form_MouseUp(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                _leftFlag = false;
            }
        }

        private void pictureEdit_exit_MouseHover(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexit;
            Cursor = Cursors.Hand;
        }

        private void pictureEdit_exit_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexitPressDown;

            Cursor = Cursors.Arrow;

        }
        private void btn_MouseHover(object sender, EventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void btn_MouseLeave(object sender, EventArgs e)
        {
            Cursor = Cursors.Arrow;
        }

        private void pictureEdit_exit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Form_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Close();
            }
        }

        private void txtEdt_condition_KeyPress(object sender, KeyPressEventArgs e)
        {          
            if ((Keys)e.KeyChar == Keys.Enter)
            {
                simpleButton_Select_Click(null, null);
            }         
        }
    }
}